import { EggAppConfig, EggAppInfo, PowerPartial } from "egg";
import * as dotenv from "dotenv";
dotenv.config();

export default (appInfo: EggAppInfo) => {
  const config = {} as PowerPartial<EggAppConfig>;

  // override config from framework / plugin
  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + "_1652521338106_9568";

  // add your egg config in here
  config.middleware = [];

  // add your special config in here
  const bizConfig = {
    sourceUrl: `https://github.com/eggjs/examples/tree/master/${appInfo.name}`,
  };

  // crsf安全请求保护
  config.security = {
    csrf: {
      enable: false,
    },
    domainWhiteList: ["http://localhost:8080"],
  };

  config.validate = {
    // 配置参数校验器，基于parameter
    convert: true, // 对参数可以使用 convertType 规则进行类型转换
    // validateRoot: false,   // 限制被验证值必须是一个对象。
    widelyUndefined: true, // 强制把"'', NaN, Null 等转为undefined
  };

  // bcrypt密码加配置
  config.bcrypt = {
    saltRounds: 10,
  };

  // jwt插件配置

  // redis插件配置

  // egg-mongoose插件配置

  // the return config will combines to EggAppConfig
  return {
    ...config,
    ...bizConfig,
  };
};
